home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / C⁄C++ OS8 / LayerGroups / PopupGroupBox.cp < prev    next >
Encoding:
Text File  |  1998-10-23  |  7.1 KB  |  364 lines  |  [TEXT/CWIE]

  1. // PopupGroupBox.cp
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15.  
  16. #include "Globals.h"
  17. #include "ResourceDefs.h"
  18. #include "DoScrap.h"
  19. #include "Miscellany.h"
  20. #include "Scrolling.h"
  21. #include "ControlUtils.h"
  22. #include "DDocData.h"
  23. #include "LayerGroupsEngine.h"
  24. #include "LayerGroupsDoc.h"
  25.  
  26. #include "PopupGroupBox.h"
  27.  
  28.  
  29. //----------
  30. void    PopupGroupBox::Create (
  31.     AMDoc*            inDoc,
  32.     DDocData*        inData)
  33. {
  34.     PopupGroupBox*        winObj = new PopupGroupBox;
  35.  
  36.     if (winObj != nil) {
  37.         winObj->Open (inDoc);
  38.         winObj->ConnectToData (inData);
  39.     }
  40. }
  41.  
  42. //----------
  43. PopupGroupBox::PopupGroupBox ()
  44. {
  45.     mData = nil;
  46. }
  47.  
  48. //----------
  49. PopupGroupBox::~PopupGroupBox ()
  50. {
  51. }
  52.  
  53. //----------
  54. LayerGroupsEngine*    PopupGroupBox::GetEngine ()
  55. {
  56.     return (LayerGroupsEngine*) mDoc->mEngine;
  57. }
  58.  
  59. //----------
  60. void    PopupGroupBox::Open (
  61.     AMDoc*            inDoc)
  62. {
  63.     WindowPtr        window;
  64.     Handle            wftb;
  65.  
  66.     mDoc = inDoc;
  67.  
  68.     window = GetNewCWindow (WIND_PopupGroupBox, nil, (WindowPtr) -1L);
  69.     if (mDoc->mEngine->GetFilename () [0] != 0) {
  70.         SetWTitle (window, mDoc->mEngine->GetFilename ());
  71.     }
  72.     mWindow = window;
  73.     ((LayerGroupsDoc*)mDoc)->mPopupGroupBoxPtr = window;
  74.  
  75.     SetWindowKind (window, 'AM');
  76.     SetWRefCon (window, (long) this);
  77.     SetPort (window);
  78.     SetInfo (window);
  79.  
  80.     wftb = ::GetResource ('Wftb', WIND_PopupGroupBox);
  81.  
  82.     CreateRootControl (window, &mRootControl);
  83.  
  84.     vScroll = nil;
  85.     hScroll = nil;
  86.  
  87.  
  88.  
  89.     mGroupBoxHandle = ::GetNewControl (CNTL_GroupBox, window);
  90.     SetWindowItemFont (mGroupBoxHandle, wftb, 1);
  91.  
  92.     mPopupLayersHandle = ::GetNewControl (CNTL_PopupLayers, window);
  93.     EmbedControl (mPopupLayersHandle, mGroupBoxHandle);
  94.     SetWindowItemFont (mPopupLayersHandle, wftb, 2);
  95.  
  96.  
  97.     mAlphaHandle = ::GetNewControl (CNTL_Alpha, window);
  98.     EmbedControl (mAlphaHandle, mPopupLayersHandle);
  99.     SetWindowItemFont (mAlphaHandle, wftb, 3);
  100.  
  101.     mChooseFromThePopupToSeeOtLabel = GetNewControl (CNTL_ChooseFromThePopupToSeeOt, window);
  102.     EmbedControl (mChooseFromThePopupToSeeOtLabel, mAlphaHandle);
  103.     SetWindowItemFont (mChooseFromThePopupToSeeOtLabel, wftb, 4);
  104.     SetControlFromTEXT (mChooseFromThePopupToSeeOtLabel, TEXT_ChooseFromThePopupToSeeOt);
  105.  
  106.  
  107.     mBetaHandle = ::GetNewControl (CNTL_Beta, window);
  108.     EmbedControl (mBetaHandle, mPopupLayersHandle);
  109.     SetWindowItemFont (mBetaHandle, wftb, 5);
  110.  
  111.     mProgressBarHandle = ::GetNewControl (CNTL_ProgressBar, window);
  112.     EmbedControl (mProgressBarHandle, mBetaHandle);
  113.     SetWindowItemFont (mProgressBarHandle, wftb, 6);
  114.     SetIndeterminateState (mProgressBarHandle, true);
  115.  
  116.  
  117.     mGammaHandle = ::GetNewControl (CNTL_Gamma, window);
  118.     EmbedControl (mGammaHandle, mPopupLayersHandle);
  119.     SetWindowItemFont (mGammaHandle, wftb, 7);
  120.  
  121.     mEditText3Handle = ::GetNewControl (CNTL_EditText3, window);
  122.     EmbedControl (mEditText3Handle, mGammaHandle);
  123.     SetWindowItemFont (mEditText3Handle, wftb, 8);
  124.  
  125.     AdvanceKeyboardFocus (window);
  126.  
  127.     ShowWindow (window);
  128. }
  129.  
  130. //----------
  131. void    PopupGroupBox::Close ()
  132. {
  133.     mData->RemoveResponder (this);
  134.  
  135.     ((LayerGroupsDoc*)mDoc)->mPopupGroupBoxPtr = nil;
  136.     SetInfo (nil);
  137.     HideWindow (mWindow);
  138.     DisposeWindow (mWindow);
  139.  
  140.     delete this;
  141. }
  142.  
  143. //----------
  144. void    PopupGroupBox::ConnectToData (
  145.     DDocData*        inData)
  146. {
  147.     mData = inData;
  148.     mData->AddResponder (this);
  149.  
  150.     SetControlValue (mGroupBoxHandle, mData->GetPopupChoice ());
  151.     SetLayerGroupValue (mPopupLayersHandle, mData->GetPopupChoice ());
  152.     SetControlValue (mProgressBarHandle, mData->GetProgressBar ());
  153.     SetControlText (mEditText3Handle, mData->GetEditText3 ());
  154. }
  155.  
  156. //----------
  157. void    PopupGroupBox::DataChanged (
  158.     long        inDataID)
  159. {
  160.     if (inDataID == idPopupChoice) {
  161.         SetControlValue (mGroupBoxHandle, mData->GetPopupChoice ());
  162.     }
  163.     if (inDataID == idPopupChoice) {
  164.         SetLayerGroupValue (mPopupLayersHandle, mData->GetPopupChoice ());
  165.     }
  166.     if (inDataID == idProgressBar) {
  167.         SetControlValue (mProgressBarHandle, mData->GetProgressBar ());
  168.     }
  169.     if (inDataID == idEditText3) {
  170.         SetControlText (mEditText3Handle, mData->GetEditText3 ());
  171.     }
  172. }
  173.  
  174. //----------
  175. void    PopupGroupBox::Control (
  176.     ControlHandle        whichControl,
  177.     short                whichPart,
  178.     Point                where)
  179. {
  180.     Rect            bounds;
  181.     short            newValue;
  182.  
  183.     ExitCurField ();
  184.  
  185.     if (whichControl == mGroupBoxHandle) {
  186.         if (HandleControlClick (mGroupBoxHandle, where,
  187.                                 (short)curEvent.modifiers,
  188.                                 (ControlActionUPP)(-1)) != 0) {
  189.             mData->SetPopupChoice (GetControlValue (mGroupBoxHandle));
  190.         }
  191.     }
  192.     if (whichControl == mEditText3Handle) {
  193.         HandleEditClick (mEditText3Handle, where);
  194.         // mData->SetEditText3 (GetEditTextChars (mEditText3Handle));
  195.         // wait 'til exit field
  196.     }
  197. }
  198.  
  199. //----------
  200. void    PopupGroupBox::MouseIn (
  201.     Point        where,
  202.     short        modifiers)
  203. {
  204.     Rect        bounds;
  205.  
  206. }
  207.  
  208. //----------
  209. void    PopupGroupBox::ExitCurField ()
  210. {
  211.     ControlHandle    focus;
  212.  
  213.     GetKeyboardFocus (mWindow, &focus);
  214.  
  215.     if (focus == nil) {
  216.         // nothing to exit
  217.  
  218.     } else if (focus == mEditText3Handle) {
  219.         mData->SetEditText3 (GetEditTextChars (mEditText3Handle));
  220.     }
  221. }
  222.  
  223. //----------
  224. void    PopupGroupBox::TypeIn (
  225.     char        ch)
  226. {
  227.     ControlHandle    focus;
  228.     SInt16            keyCode;
  229.  
  230.     GetKeyboardFocus (mWindow, &focus);
  231.  
  232.     if ((ch == charEnter)
  233.     ||  (ch == charReturn)) {
  234.         ExitCurField ();
  235.     } else if (ch == charEsc) {
  236.     } else if (ch == charTab) {
  237.         DoTab ((curEvent.modifiers & optionKey) != 0);
  238.     } else if (focus != nil) {
  239.         keyCode = (SInt16)(curEvent.message & keyCodeMask);
  240.         HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
  241.         mDoc->mEngine->SetDirty ();
  242.     } else {
  243.         SysBeep (1);
  244.     }
  245. }
  246.  
  247. //----------
  248. void    PopupGroupBox::Resize ()
  249. {
  250.     /* application-specific code to resize items in window */
  251. }
  252.  
  253. //----------
  254. void    PopupGroupBox::Scroll (
  255.     short        newValue,
  256.     short        oldValue)
  257. {
  258.     /* application-specific code to scroll window */
  259.     if (gWhichScroll == vScroll) {
  260.     } else {    // horizontal
  261.     }
  262. }
  263.  
  264. //----------
  265. void    PopupGroupBox::DoUndo ()
  266. {
  267. } // DoUndo
  268.  
  269. //----------
  270. void    PopupGroupBox::DoCut ()
  271. {
  272.     TEHandle        curTE = GetCurTE ();
  273.  
  274.     if (curTE != nil) {
  275.         TECut (curTE);
  276.         mDoc->mEngine->SetDirty ();
  277.         scrapDirty = true;
  278.     }
  279. } // DoCut
  280.  
  281. //----------
  282. void    PopupGroupBox::DoCopy ()
  283. {
  284.     TEHandle        curTE = GetCurTE ();
  285.  
  286.     if (curTE != nil) {
  287.         TECopy (curTE);
  288.         scrapDirty = true;
  289.     }
  290. } // DoCopy
  291.  
  292. //----------
  293. void    PopupGroupBox::DoPaste ()
  294. {
  295.     TEHandle        curTE = GetCurTE ();
  296.  
  297.     if (curTE != nil) {
  298.         TEPaste (curTE);
  299.         mDoc->mEngine->SetDirty ();
  300.     }
  301. } // DoPaste
  302.  
  303. //----------
  304. void    PopupGroupBox::DoClear ()
  305. {
  306.     TEHandle        curTE = GetCurTE ();
  307.  
  308.     if (curTE != nil) {
  309.         TEDelete (curTE);
  310.         mDoc->mEngine->SetDirty ();
  311.     }
  312. } // DoClear
  313.  
  314. //----------
  315. void    PopupGroupBox::DoSelectAll ()
  316. {
  317.     TEHandle        curTE = GetCurTE ();
  318.  
  319.     if (curTE != nil) {
  320.         TESetSelect (0, 32767, curTE);
  321.     }
  322. } // DoSelectAll
  323.  
  324. //----------
  325. void    PopupGroupBox::DoShowClipboard ()
  326. {
  327. } // DoShowClipboard
  328.  
  329. //----------
  330. Boolean        PopupGroupBox::DoCommand (
  331.     long        inCommand)
  332. {
  333.     Boolean        result = true;
  334.  
  335.     switch (inCommand) {
  336.         case cmdUndo:
  337.                 DoUndo ();
  338.             break;
  339.         case cmdCut:
  340.                 DoCut ();
  341.             break;
  342.         case cmdCopy:
  343.                 DoCopy ();
  344.             break;
  345.         case cmdPaste:
  346.                 DoPaste ();
  347.             break;
  348.         case cmdClear:
  349.                 DoClear ();
  350.             break;
  351.         case cmdSelectAll:
  352.                 DoSelectAll ();
  353.             break;
  354.         case cmdShowClipboard:
  355.                 DoShowClipboard ();
  356.             break;
  357.  
  358.         default:
  359.                 result = false;
  360.     } // switch
  361.  
  362.     return result;
  363. }
  364.